// 解法一
var detectCycle = function(head) {
    // if(!head || !head.next) return  null;
    let index = 0;
    while(head) {
        if(head.flag) {
            return head;
        }
        head.flag = true;
        head.index = index;
        head = head.next;
        index=++index;
    }
    return null;
};
// 解法二
var detectCycle = function(head) {
    if(!head || !head.next) return null;
    let slow =head.next, fast = head.next.next;
    while(fast && fast.next) {
        slow = slow.next;
        fast = fast.next.next;
        if(fast == slow) {
            slow = head;
            while (fast !== slow) {
                slow = slow.next;
                fast = fast.next;
            }
            return slow;
        }
    }
    return null;
}